package com.goodfather.textbook.youdao.pad.bean;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

public class Sentence implements Parcelable, Comparable<Sentence> {
    public int sentenceId;
    public int kindId;//筛选 id为1 和2(表示可以点读数据)
    public String beginTime;//开始时间：秒
    public String endTime;
    public String startX;
    public String startY;
    public String endX;
    public String endY;
    public String displayEn;
    public String displayCn;
    public String choice;
    public String solution;
    public String lessonId;
    public String audioUrl;
    public int pageNo;

    protected Sentence(Parcel in) {
        sentenceId = in.readInt();
        kindId = in.readInt();
        beginTime = in.readString();
        endTime = in.readString();
        startX = in.readString();
        startY = in.readString();
        endX = in.readString();
        endY = in.readString();
        displayEn = in.readString();
        displayCn = in.readString();
        choice = in.readString();
        solution = in.readString();
        lessonId = in.readString();
        audioUrl = in.readString();
        pageNo = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(sentenceId);
        dest.writeInt(kindId);
        dest.writeString(beginTime);
        dest.writeString(endTime);
        dest.writeString(startX);
        dest.writeString(startY);
        dest.writeString(endX);
        dest.writeString(endY);
        dest.writeString(displayEn);
        dest.writeString(displayCn);
        dest.writeString(choice);
        dest.writeString(solution);
        dest.writeString(lessonId);
        dest.writeString(audioUrl);
        dest.writeInt(pageNo);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Sentence> CREATOR = new Creator<Sentence>() {
        @Override
        public Sentence createFromParcel(Parcel in) {
            return new Sentence(in);
        }

        @Override
        public Sentence[] newArray(int size) {
            return new Sentence[size];
        }
    };

    @Override
    public int compareTo(@NonNull Sentence o) {
        // (-0.0, 0.0) or (!NaN, NaN) cannot to be compared
        double beginTime1 = Double.parseDouble(this.beginTime);
        String lessonId1 = this.lessonId;

        double beginTime2 = Double.parseDouble(o.beginTime);
        String lessonId2 = o.lessonId;

        if (lessonId1.equals(lessonId2)) {
            return Double.compare(beginTime1, beginTime2);
        } else {
            return lessonId1.compareTo(lessonId2);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Sentence sentence = (Sentence) o;

        if (sentenceId != sentence.sentenceId) return false;
        return lessonId != null ? lessonId.equals(sentence.lessonId) : sentence.lessonId == null;

    }

}
